﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace Flare.Pages.Endpoint
{
    public partial class Edit : UserControl, ITypicalPage
    {
        public string name
        {
            get { return "Редактирование"; }
        }

        int _id;

        public Edit(int ep_id)
        {
            _id = ep_id;
            this.DataContext = new Flare.DB.endpoints().Details(ep_id);
            InitializeComponent();
        }

        private void Department_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ((ObjectDataProvider)this.Resources["general_roomsDataSet"]).MethodParameters[0] = (int?)Department.SelectedValue;
        }

        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            var data = new DB.Entity.Endpoint()
            {
                id = _id,
                id_room = (int?)Room.SelectedValue,
                id_type = (int?)netType.SelectedValue,
                name = endpoint_name.Text,
                net_ip = endpoint_ip.Text,
                phone = endpoint_phone.Text
            };

            try
            {
                new DB.endpoints().Edit(data);
                saveButton.ShowResult();
            }
            catch (Exception ex)
            {
                glob.kernel.ShowNotice(ex.Message);
            }
        }

    }
}
